﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ERPStore.MockConnector
{
	public class EmailerService : ERPStore.Services.EmailerService
	{

		public EmailerService(Logging.ILogger logger
			, ERPStore.Services.CryptoService cryptoService
			, ERPStore.Services.IScheduledTaskService taskService
			)
			: base(logger)
		{
		}

		public override void Send(System.Net.Mail.MailMessage message)
		{
			var smtpClient = new System.Net.Mail.SmtpClient();
			if (smtpClient.DeliveryMethod == System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory
					&& smtpClient.PickupDirectoryLocation == @".\")
			{
				var path = this.GetType().Assembly.Location;
				var fileName = System.IO.Path.GetFileName(path);
				path = path.Replace(fileName, string.Empty);
				var mailPath = System.IO.Path.Combine(path, "Emails");
				if (!System.IO.Directory.Exists(mailPath))
				{
					System.IO.Directory.CreateDirectory(mailPath);
				}
				smtpClient.PickupDirectoryLocation = mailPath;
			}

			smtpClient.Send(message);
		}
	}
}
